package svc

import (
	"gorm.io/driver/mysql"
	"gorm.io/gorm"
	"log"
	"study/internal/config"
)

type ServiceContext struct {
	Config config.Config
	DB     *gorm.DB // 添加 GORM 数据库连接
}

func NewServiceContext(c config.Config) *ServiceContext {

	// 使用 GORM 连接数据库
	db, err := gorm.Open(mysql.Open(c.Mysql.DataSource), &gorm.Config{})
	if err != nil {
		log.Fatalf("failed to connect database: %v", err)
	}

	return &ServiceContext{
		Config: c,
		DB:     db,
	}
}
